<?php

namespace app\http\middleware;
use think\Db;
class CheckLogin
{
    public function handle($request, \Closure $next)
    {
    	if (!($token = $request->header('Token')) || strpos($token, '.') === false) 
    	{
    		return json(['code' => 1,'mes' => '请先登录']);
    	}
    	$user = Db::name('user')->where('user_token',$token)->find();
    	if(!$user) return json(['code' => 1, 'mes' => '请先登录']);
    	$request->user = $user;
    	return $next($request);
    }
}
